package com.cat.dataStructure02;

import java.util.Arrays;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/power-of-heroes/
 * @create 2025/10/13 20:50
 * @since JDK17
 */

public class Solution16 {
    public int sumOfPower(int[] nums) {
        Arrays.sort(nums);  // 这样可以比较快速的求出最大值和最小值
        long ans = 0, s = 0;
        int N = (int) (1e9 + 7);
        for (long x : nums) {
            ans = (ans + x * x % N * (x + s)) % N;
            s = (s * 2 + x) % N;
        }

        return ((int) ans);
    }
}
